<template>
  <el-card class="common-container">
    <div style="margin-bottom: 20px; font-size: 20px;color: #606266;">模板管理</div>
    <div class="search-container">
      <!--      <el-input v-model="title" class="search-wrap" />-->
      <!--      <el-button type="primary" icon="search" @click="getList">查询</el-button>-->
      <el-button class="addBtn" type="primary" icon="add" @click="handleAdd">添加模板</el-button>
    </div>
    <el-table :data="list" border>
      <el-table-column prop="title" label="标题" />
      <el-table-column prop="templateIdShort" label="模板ID" />
      <el-table-column prop="templateType" width="150px" label="模板类型">
        <template slot-scope="scope">
          <span v-if="scope.row.templateType === 0">公众号模板消息</span>
          <span v-if="scope.row.templateType === 1">小程序模板消息(停用)</span>
          <span v-if="scope.row.templateType === 2">小程序订阅消息</span>
        </template>
      </el-table-column>
      <el-table-column prop="class1" label="行业">
        <template slot-scope="scope">
          <div><span v-if="scope.row.class1"> {{ scope.row.class1 }} / </span> {{ scope.row.class2 }}</div>
        </template>
      </el-table-column>

      <el-table-column prop="description" label="说明" />
      <el-table-column prop="createTime" label="创建时间" />
      <el-table-column align="center" label="操作" width="250px">
        <template slot-scope="scope">
          <el-button class="editBtn" size="small" type="primary" @click="handleEdit(scope.row.id)">编辑</el-button>
          <el-button size="small" type="warning" @click="handleSend(scope.row.id)">测试</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      style="margin-top: 10px "
      background
      :current-page.sync="pageNum"
      :page-size.sync="pageSize"
      layout="total, prev, pager, next"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </el-card>
</template>

<script>
import { listTemplate } from '@/api/wxTemplateMsg'

export default {
  name: 'TemplateMsg',
  data() {
    return {
      // title: null, // 搜索内容
      pageNum: 0,
      pageSize: 10,
      list: [],
      total: 0
    }
  },
  mounted() {
    this.getList()
  },

  methods: {
    getList() {
      listTemplate({ pageNum: this.pageNum, pageSize: this.pageSize }).then((res) => {
        this.list = res.data.list
        this.total = res.data.total
        return res
      })
    },
    handleAdd() {
      this.$router.push({ name: 'addTemplateMsg' })
    },
    handleSizeChange() {
    },

    handleCurrentChange() {
      this.getList()
    },

    handleEdit(id) {
      this.$router.push({ name: 'editTemplateMsg', params: { id: id } })
    },
    handleSend(id) {
      this.$router.push({ name: 'templateMsgSend', params: { id: id } })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .search-container {
    margin-top: 20px;
    margin-bottom: 20px
  }
  .search-wrap {
    width: 300px;
    margin-right: 10px
  }
  .addBtn{
	  background-color: $btnBgc;
	  border-color: $btnBgc;
  }
  .addBtn:hover{
	  opacity: 0.5;
  }
  .editBtn{
	  background-color: $warning;
	  border-color: $warning;
  }
  ::v-deep .el-pagination.is-background .el-pager li:not(.disabled).active{
	  background-color: $btnBgc;
  }
  ::v-deep .el-pagination.is-background .el-pager li:not(.disabled):hover{
		color: white;
		background-color: $btnBgc;
	}
</style>
